<?php
if( !function_exists('b_sitemap_links') )
{
	require_once realpath(dirname(__FILE__)) . '/../class/links_Base.class.php';

	function b_sitemap_links($mydirname)
	{
		$myts =& MyTextSanitizer::getInstance();

		// $Links OBJ
		$links_base = links_Base::getInstance($mydirname);

		$firstCids = $links_base->Categories->getFirstChild(0,"corder,cid");

		$options = $links_base->uri_option_arr;
		$url_approach = $options['url_approach'];
		$url_suffix = $options['url_suffix'];

		switch ($url_approach) {
			case 1:
			case 2:
			case 3:
				$base_url = 'category/index/';
				if ($url_approach !=2) {
					$base_url = 'index.php/'. $base_url;
				}
				break;
			case 0:
			default:
				$base_url = 'index.php?c=category&amp;cid=';
				break;
		}
		$url_suffix = ($url_approach > 0 &&  $url_suffix) ? $url_suffix: '';

		$ret = array();
		foreach ( $firstCids as $cat ) {
			$cid = intval($cat['cid']);
			$ret["parent"][] = array(
				"id"    => $cid,
				"title" => $cat['title'],
				"url"   => $base_url . $cid . $url_suffix,
			) ;
		}

		return $ret;
	}

}

